<?php
declare(strict_types=1);

namespace App\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Controller;
use App\Middleware\WebApiMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use Service\MemberService\MemberBasicService;
use Hyperf\Di\Annotation\Inject;

/**
 * 用户基础信息
 * @author huj
 * @Controller(prefix="/webapi/v1/memberinfo")
 * @Middleware(WebApiMiddleware::class)
 */
class MemberBasicController extends AbstractController 
{
    /**
     * 通过 `@Inject` 注解注入由 `@var` 注解声明的属性类型对象
     * @Inject()
     * @var MemberBasicService
     */
    protected $memberBasicService;

    /**
     * 个人资料
     * @RequestMapping(path="index", methods="get,post")
     */
    public function index(RequestInterface $request)
    {
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberBasicService->memberInfo($param);
    }

    /**
     * 修改用户信息
     * @RequestMapping(path="edit", methods="get,post")
     */
    public function edit(RequestInterface $request)
    {
        $param        = $request->inputs(['nickname','avatar']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberBasicService->editInfo($param);
    }

    /**
     * 实名认证
     * @RequestMapping(path="editAuth", methods="get,post")
     */
    public function editAuth(RequestInterface $request)
    {
        $param        = $request->inputs(['true_name', 'idcard','card_front','card_back','cid','mobile']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberBasicService->editAuth($param);
    }

    /**
     * 获取实名信息
     * @RequestMapping(path="authInfo", methods="get,post")
     */
    public function authInfo(RequestInterface $request)
    {
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberBasicService->authInfo($param);
    }

    /**
     * 绑定导购员
     * @RequestMapping(path="bindGuide", methods="get,post")
     */
    public function bindGuide(RequestInterface $request)
    {
        $param        = $request->inputs(['invite_code', 'mn_sid','mnid','cid']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberBasicService->bindGuide($param);
    }

    /**
     * 查询导购员
     * @RequestMapping(path="getGuide", methods="get,post")
     */
    public function getGuide(RequestInterface $request)
    {
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberBasicService->getGuide($param);
    }
}